<?php
declare(strict_types=1);

namespace Plugin\Alarm\Repository;

use App\Repository\IRepository;
use Hyperf\Collection\Arr;
use Hyperf\Database\Model\Builder;
use Plugin\Alarm\Model\RdAlarmWorkApply;

class RdAlarmWorkApplyRepository extends IRepository
{
    public function __construct(protected readonly RdAlarmWorkApply $model)
    {
    }

    public function handleSearch(Builder $query, array $params): Builder
    {
        if ($id = Arr::get($params, 'id')) {
            $query->whereIn('id', Arr::wrap($id));
        }
        
        if ($workId = Arr::get($params, 'work_id')) {
            $query->where('work_id', $workId);
        }
        
        if ($userId = Arr::get($params, 'user_id')) {
            $query->where('user_id', $userId);
        }
        
        if ($status = Arr::get($params, 'status')) {
            $query->where('status', $status);
        }

        return $query;
    }
}